/******************************************************************************************************
Copyright (C) 2008 Mestrelab Research S.L. All rights reserved.

This file is part of the MNova scripting toolkit.

Authorized users of MNova Software may use this file freely, but this file is provided AS IS
with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE.
*****************************************************************************************************/
// This example function demonstrates how to apply some processing to the spectra already opened in MestReNova. 
// It applies a specific processing dependently on the spectrum nucleus and dimensionality values.
function process_each_opened_spectrum()
{
	var dw = new DocumentWindow(Application.mainWindow.activeWindow());
	var pageCount = dw.pageCount();
	for(var i = 0; i < pageCount; i++)
	{
		var page = new Page(dw.page(i));
		var itemCount = page.itemCount();
		for(var j = 0; j < itemCount; j++)
		{
			var spec = new NMRSpectrum(page.item(j));
			if (spec.isValid()) // if page item is a spectrum
			{
				print("Item #" + j + " is " + spec.dimCount + "D spectrum.");
				var processing = new String;
				if (spec.dimCount == 1)
				{
					if (spec.nucleus() == "1H")
						processing = "c:/process/_test.mnp";
					else if (spec.nucleus() == "13C")
						processing = "c:/process/13C.mnp";
				}
				else if (spec.dimCount == 2)
				{
					if (spec.nucleus(1) == "1H" && spec.nucleus(2) == "1H")
						processing = "c:/process/COSY.mnp";
				}
				if (!processing.isEmpty())
					nmr.processSpectrum(spec, processing);
				else
					print("Spectrum #" + j + " was not processed.");
			}
			else
			{
				print("Item #" + j + " is not a spectrum.")
			}
		}
	}
}